import Vue from 'vue'
import App from './App'

import uView from 'uview-ui';
Vue.use(uView);

import navgation from './components/navigation/navigation.vue'
Vue.component('navgation', navgation)

import $H from './common/request.js';
Vue.prototype.$H = $H

import {
	api
} from './common/api.js';
Vue.prototype.$api = api

import imageUrl from './common/config.js';
Vue.prototype.$imgUrl = imageUrl.imageUrl

import store from './store/index.js';
Vue.prototype.$store = store

import navBar from './components/navBar/navBar.vue'
Vue.component('navBar', navBar)

import cloudEmpty from "components/cloud-empty/cloud-empty"
Vue.component('cloud-empty', cloudEmpty)

//挂在全局组件
import LoginPop from './components/login-pop.vue'
Vue.component('LoginPop', LoginPop)

Vue.prototype.msg = (msg) => {
	uni.showToast({
		title: msg,
		icon: 'none'
	});
}

Vue.prototype.authJump = (options) => {
	console.log(store)
	if (!store.state.token) {
		uni.showToast({
			title: '请先登录',
			icon: 'none'
		});
		return uni.navigateTo({
			url: '/pages/login/login'
		});
	}
	uni.navigateTo(options);
}

Vue.prototype.jump = (options) => {
	uni.navigateTo(options);
}

Vue.prototype.switchTab = (options) => {
	uni.switchTab(options);
}

Vue.prototype.tel = (options) => {
	uni.makePhoneCall({
		phoneNumber: options
	});
}

// 判断是否为空 返回true/false
Vue.prototype.isBlank = (data) => {
	if (data == null || data === 'null' || data === '' || data === undefined || data === 'undefined' || data ===
		'unknown') {
		return true
	} else {
		return false
	}
}

Vue.prototype.getImgUrl = (image) => {
	return imageUrl.imageUrl + image
}

Vue.prototype.tomapapp = (latitude, longitude, name) => {
	//打开第三方地图
	let url = "";
	if (plus.os.name == "Android") { //判断是安卓端
		plus.nativeUI.actionSheet({ //选择菜单
			title: "选择地图应用",
			cancel: "取消",
			buttons: [{
				title: "腾讯地图"
			}, {
				title: "百度地图"
			}, {
				title: "高德地图"
			}]
		}, function(e) {
			switch (e.index) {
				//下面是拼接url,不同系统以及不同地图都有不同的拼接字段
				case 1:
					//注意referer=xxx的xxx替换成你在腾讯地图开发平台申请的key
					url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
					break;
				case 2:
					url =
						`baidumap://map/marker?location=${latitude},${longitude}&title=${name}&coord_type=gcj02&src=andr.baidu.openAPIdemo`;
					break;
				case 3:
					url =
						`androidamap://viewMap?sourceApplication=appname&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
					break;
				default:
					break;
			}
			if (url != "") {
				url = encodeURI(url);
				//plus.runtime.openURL(url,function(e){})调起手机APP应用
				plus.runtime.openURL(url, function(e) {
					plus.nativeUI.alert("本机未安装指定的地图应用");
				});
			}
		})
	} else {
		// iOS上获取本机是否安装了百度高德地图，需要在manifest里配置
		// 在manifest.json文件app-plus->distribute->apple->urlschemewhitelist节点下添加
		//（如urlschemewhitelist:["iosamap","baidumap"]）  
		plus.nativeUI.actionSheet({
			title: "选择地图应用",
			cancel: "取消",
			buttons: [{
				title: "腾讯地图"
			}, {
				title: "百度地图"
			}, {
				title: "高德地图"
			}]
		}, function(e) {
			switch (e.index) {
				case 1:
					url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
					break;
				case 2:
					url =
						`baidumap://map/marker?location=${latitude},${longitude}&title=${name}&content=${name}&src=ios.baidu.openAPIdemo&coord_type=gcj02`;
					break;
				case 3:
					url =
						`iosamap://viewMap?sourceApplication=applicationName&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
					break;
				default:
					break;
			}
			if (url != "") {
				url = encodeURI(url);
				plus.runtime.openURL(url, function(e) {
					plus.nativeUI.alert("本机未安装指定的地图应用");
				});
			}
		})
	}

}


Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
	store,
	...App
})
app.$mount()
